package com.css.fxfzmh.modules.templateManage.service.impl;

import com.css.fxfzmh.constants.YNEnum;
import com.css.fxfzmh.modules.templateManage.entity.Template;
import com.css.fxfzmh.modules.templateManage.param.TemplateParam;
import com.css.fxfzmh.modules.templateManage.repository.TemplateRepository;
import com.css.fxfzmh.modules.templateManage.service.TemplateService;
import com.css.fxfzmh.util.CreateGson;
import com.css.fxfzmh.util.UUIDGenerator;
import com.css.fxfzmh.web.PlatformSessionContext;
import com.css.fxfzmh.zcpt.sys.entity.SUser;
import com.css.fxfzmh.zcpt.sys.service.impl.SUserServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

/**
 * @Author: zhangSongRui
 * @CreateTime: 2023/05/10
 * @Description: 图件模板Service
 */
@Service
public class TemplateServiceImpl implements TemplateService {

    @Resource
    TemplateRepository templateRepository;
    @Resource
    SUserServiceImpl sUserServiceImpl;

    @Override
    public Map<String, Object> getPage(int curPage, int pageSize, TemplateParam param) {
        return templateRepository.getPage(curPage,pageSize,param);
    }

    @Override
    public void save(Template template) {
        template.setId(UUIDGenerator.getUUID());
        template.setCreateUser(PlatformSessionContext.getUserID());
        template.setCreateTime(new Date());
        template.setDelFlag(YNEnum.N.toString());
        //获取用户名称
        String sUser = sUserServiceImpl.getSUser(PlatformSessionContext.getUserID());
        SUser userInfo = CreateGson.createGson().fromJson(sUser, SUser.class);
        template.setUserName(userInfo.getUserName());
        templateRepository.save(template);
    }

    @Override
    public void delete(String ids) {
        templateRepository.delete(Arrays.asList(ids.split(",")));
    }
}
